home *** CD-ROM | disk | FTP | other *** search
/ Macromedia Multimedia Showcase 5.1 / Macromedia - Multimedia Showcase 5.1 (Macromedia) (1996).ISO / pc / media / shared.dir / 02019_Script_Finder Object < prev    next >
Text File  |  1996-03-28  |  5KB  |  168 lines

  1. -- script for "Finder Object"
  2.  
  3. property scrollUpButtonSprite, scrollDownButtonSprite, whichFinder, prefixField, addrField, ¼
  4.           currentAddrList, currentPrefix, currentFieldValue, currentAddrNum
  5.  
  6. global gNavObj
  7.  
  8. on birth me, finderType
  9.   
  10.   -- The scroll up and down button scripts are added dynamically
  11.   
  12.   global sBirthPtr, tBirthPtr, sDeathPtr, tDeathPtr, castIdPtr, scriptPtr
  13.   
  14.   set whichFinder = finderType   -- #ATP or #MAGIC
  15.   set prefixField = "prefix"
  16.   set addrField = "Finder Result"
  17.   set buttonList = [ "bUp", "bDown" ]
  18.   set scriptList = [ "findPrevAddress", "findNextAddress" ]
  19.   set scrollUpButtonSprite = 30
  20.   set scrollDownButtonSprite = 31
  21.   set myEvent = string( the curEvent of gNavObj )
  22.   set birthScene = item sBirthPtr of myEvent
  23.   put birthScene into item sDeathPtr of myEvent
  24.   put "end" into item tDeathPtr of myEvent
  25.   repeat with buttonNum = 1 to count(buttonList)
  26.     put getAt(buttonList,buttonNum) into item castIdPtr of myEvent
  27.     put getAt(scriptList,buttonNum) into item scriptPtr of myEvent
  28.     -- put "in finder object"
  29.     DrawBtn (gNavObj, myEvent, "#AddFinderObj")
  30.   end repeat
  31.   set currentPrefix = "415"
  32.   put currentPrefix into field prefixField
  33.   set currentFieldValue = currentPrefix
  34.   setAddrList(me, currentPrefix)
  35.   set currentAddrNum = 1
  36.   getAddress(me)
  37.   return me
  38.   
  39. end birth
  40.  
  41. -- 
  42.  
  43. on kill me
  44.   put " " into field prefixField
  45.   set the textSize of field prefixField = 18
  46.   set the textStyle of field prefixField to "bold"
  47.   put " " into field addrField
  48.   set the textSize of field addrField = 12
  49.   set the textStyle of field addrField to "plain"
  50. end kill
  51.  
  52. -- 
  53.  
  54. on getAddress me
  55.   if currentAddrList = [ ] then return
  56.   set addrInfo = getAt(currentAddrList, currentAddrNum)
  57.   if whichFinder = "#ATP" or whichFinder = #ATP then
  58.     set layout = [ [1], [2,", ",3,",  ",4], ["(",5,") ",6], [7] ]
  59.   else
  60.     set layout = [ [1], [2], [3,", ",4,"  ",5], [6] ]
  61.   end if
  62.   set thisAddr = ""
  63.   repeat with lineList in layout
  64.     set thisLine = ""
  65.     set itemsInLine = count(lineList)
  66.     repeat with i = 1 to itemsInLine
  67.       set whichItem = getAt(lineList,i)
  68.       if stringP(whichItem) then put whichItem after thisLine
  69.       else put getAt(addrInfo, whichItem) after thisLine
  70.       if i = itemsInLine then put RETURN after thisLine
  71.     end repeat
  72.     put thisLine after thisAddr
  73.   end repeat
  74.   delete line (the number of lines of thisAddr) of thisAddr
  75.   put thisAddr into field addrField
  76. end getAddress
  77.  
  78. -- 
  79.  
  80. on setAddrList me, aPrefix
  81.   if whichFinder = #ATP or whichFinder = "#ATP" then
  82.     set wholeList = value(field "ATP list")
  83.     set aPrefix = value(aPrefix)
  84.   else
  85.     -- MAGIC Finder
  86.     set prefStart = value(char 1 of aPrefix)
  87.     if not( (prefStart > 1) and (prefStart <= 9) ) then return 0
  88.     set theField = "MAGIC " & prefStart & "xx"
  89.     set wholeList = value(field theField)
  90.   end if
  91.   set newList = getAProp(wholeList, aPrefix)
  92.   if voidP(newList) then
  93.     set currentAddrList = [ ]
  94.     return 0
  95.   else
  96.     set currentAddrList = newList
  97.     return 1
  98.   end if  
  99. end setAddrList
  100.  
  101. -- 
  102.  
  103. on findPrevAddress
  104.   if objectP(the FinderObj of gNavObj) then
  105.     set me = the FinderObj of gNavObj
  106.     set totalAddresses = count(the currentAddrList of me)
  107.     if totalAddresses < 1 then return 0
  108.     set the currentAddrNum of me = (the currentAddrNum of me) - 1
  109.     if the currentAddrNum of me = 0 then set the currentAddrNum of me = totalAddresses
  110.     getAddress(the FinderObj of gNavObj)
  111.   end if
  112. end findPrevAddress
  113.  
  114. -- 
  115.  
  116. on findNextAddress
  117.   if objectP(the FinderObj of gNavObj) then
  118.     set me = the FinderObj of gNavObj
  119.     set totalAddresses = count(the currentAddrList of me)
  120.     if totalAddresses < 1 then return 0
  121.     set the currentAddrNum of me = (the currentAddrNum of me) + 1
  122.     if the currentAddrNum of me > totalAddresses then set the currentAddrNum of me = 1
  123.     getAddress(the FinderObj of gNavObj)
  124.   end if
  125. end findNextAddress
  126.  
  127. -- 
  128.  
  129. on selectAddr
  130.   if objectP(the FinderObj of gNavObj) then
  131.     set theField = the prefixField of (the FinderObj of gNavObj)
  132.     set numWords = the number of words of line 1 of field theField
  133.     hilite word 1 to numWords of line 1 of field theField
  134.   end if
  135. end selectAddr
  136.  
  137. -- 
  138.  
  139. on checkForNewCode me
  140.   set newPrefix = field prefixField
  141.   if (the number of chars of newPrefix > 4) or (the number of lines of newPrefix > 1) then
  142.     set newPrefix = char 1 to 4 of line 1 of newPrefix
  143.     put newPrefix into field prefixField
  144.   end if
  145.   if newPrefix <> currentPrefix then
  146.     -- check if new prefix is valid
  147.     if setAddrList(me, newPrefix) > 0 then
  148.       -- new prefix returned a valid list
  149.       set currentPrefix = newPrefix
  150.       set currentAddrNum = 1
  151.       getAddress(me)
  152.     else
  153.       set len = the number of chars in newPrefix
  154.       if len = 2 then
  155.         set thisAddr = "No companies were found within that country code."
  156.       else
  157.         if len = 3 then
  158.           set thisAddr = "No companies were found within that area code."
  159.         else
  160.           set thisAddr = "You need to enter a valid area or country code."
  161.         end if
  162.       end if
  163.       set currentPrefix = newPrefix
  164.       put thisAddr into field addrField 
  165.     end if
  166.   end if
  167. end checkForNewCode
  168.